<%@ page import="com.pijunn.label.LabeledItem" %>
<!DOCTYPE html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'labeledItem.label', default: 'Labeled Item')}" />
		<title><g:message code="default.edit.label" args="[entityName]" /></title>
		<style type="text/css" media="screen">
			textarea {
				height: 100px;
				margin: 0 15px 0 0;
			}
			input {
				margin-right: 15px;
			}
			.item-div {
				margin: 5px 0;
			}
			.label-display {
				display: inline-block;
				margin-right: 15px;
			}
			.fieldcontain {
				display: inline-block;
			}
			.no-labels p {
				font-size: 1.4em;
				color: darkseagreen;
				padding: 10px 50px;
			}
			.no-labels input {
				display:inline;
			}
		</style>
	</head>
	<body>
		<a href="#edit-labeledItem" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
				<li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
				<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
			</ul>
		</div>
		<div id="edit-labeledItem" class="content scaffold-edit" role="main">
			<h1><g:message code="default.edit.label" args="[entityName]" /></h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
			<g:hasErrors bean="${cmd}">
			<ul class="errors" role="alert">
				<g:eachError bean="${cmd}" var="error">
				<li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
				</g:eachError>
			</ul>
			</g:hasErrors>
			<g:form method="post" >
				<g:hiddenField name="id" value="${labeledItemInstance?.id}" />
				<g:hiddenField name="view" value="edit"/>
				<fieldset class="form">
					<g:if test="${labeledItemInstance }">
						<g:hiddenField name="version" value="${labeledItemInstance?.version ?: 0}" />
						<g:render template="form" model=""/>
					</g:if>
					<g:else>
						<g:each in="${labelList}" var="label" status="i">
							<g:render template='labeledItem' model="['item':label,'i':i,'hidden':false, 'cmd':cmd]"/>
						</g:each>
					</g:else>
				</fieldset>
				<fieldset class="buttons">
					<g:if test="${labeledItemInstance }">
						<g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />
					</g:if>
					<g:else>
						<g:actionSubmit class="save" action="save" value="${message(code: 'default.button.update.label', default: 'Update All')}" />
					</g:else>
					<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" formnovalidate="" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
				</fieldset>
			</g:form>
			<g:form name="delete-form" action="delete">
				<g:hiddenField name="id" value=""/>
			</g:form>
		</div>
	</body>
	<g:javascript>
	$(function(){
	
		$('.del-item').click(function(){
			var id = $(this).siblings('[name="itemId"]').val()
			var row = $(this).parent()
			if(confirm('You really want to delete the item with label: ' + $('[name="serialNumber"]', row).val() )) {
				var form = $('#delete-form')
				$('input[name="id"]').val(id);
				form.submit();
			}
		});
	});
	</g:javascript>
</html>
